const merge = require('webpack-merge');
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const base = require('./webpack.base.config')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

const PrerenderSPAPlugin = require('prerender-spa-plugin')
const Renderer = PrerenderSPAPlugin.PuppeteerRenderer


module.exports = merge(base, {
  mode: 'production',
  entry: { // 打包入口
    index: path.resolve(__dirname, '../src/prod-app.js')
  },
  output: { // 打包出口
    filename: 'js/[name].[hash:8].js',
    path: path.resolve(__dirname, '../dist'),
    publicPath: './'
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: 'index.html', // 默认储存到dist文件夹目录下
      template: './src/prod-index.html', // 添加html模板
      cache: false, // 清除缓存
      hash: true // 添加哈希值
    }),
    new MiniCssExtractPlugin({
      filename: 'css/[name].[hash:8].css', // css独立文件指定出口
    }),
    new PrerenderSPAPlugin({
      staticDir: path.join(__dirname, '../dist'),
      routes: ['/'],
      // renderer: new Renderer({
      //   headless: false,
      //   renderAfterDocumentEvent: 'render-event'
      // })
    }),
  ]
})